package com.qk.controller;

import com.github.pagehelper.Page;
import com.qk.Response.PageResult;
import com.qk.Response.Result;
import com.qk.dto.ActivityPageDTO;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    /**
     * 查询活动列表(分页)
     * @return
     */
    @GetMapping
    public Result getActivities(ActivityPageDTO activityPageDTO) {
        log.info("查询活动列表：{}",activityPageDTO);
        PageResult<Activity> pageResult =activityService.getActivities(activityPageDTO);
        return Result.success(pageResult);
    }
    /**
     * 添加活动
     * @param activity
     * @return
     */
    @PostMapping
    public Result addActivity(@RequestBody Activity activity) {
        log.info("添加活动：{}",activity);
        activityService.addActivity(activity);
        return Result.success();
    }
    /**
     * 删除活动
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteActivityById(@PathVariable Integer id){
        log.info("删除活动：{}",id);
        activityService.deleteActivityById(id);
        return Result.success();
    }
    /**
     * 修改活动
     * @param
     * @return
     */
    /*
    根据id查询活动
     */
    @GetMapping("/{id}")
    public Result selectActivityById(@PathVariable Integer id){
        log.info("查询活动：{}",id);
        Activity activity = activityService.selectActivityById(id);
        return Result.success(activity);
    }
    /**
     * 修改活动
     * @param activity
     * @return
     */
    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        log.info("修改活动：{}",activity);
        activityService.updateActivity(activity);
        return Result.success();
    }

}
